# Contributor: Celeste <cielesti@protonmail.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-mqtt
pkgver=0.2.2
pkgrel=0
pkgdesc="MQTT v3 client library"
url="https://github.com/hyper-systems/ocaml-mqtt"
arch="all !riscv64 !loongarch64" # ocaml
license="BSD-3-Clause"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-fmt-dev
	ocaml-logs-dev
	ocaml-lwt-dev
	ocaml-ocplib-endian-dev
	ocaml-tls-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	"
checkdepends="
	ocaml-alcotest-dev
	ocaml-cohttp-dev
	"
subpackages="$pkgname-dev"
source="https://github.com/hyper-systems/ocaml-mqtt/archive/refs/tags/$pkgver/ocaml-mqtt-$pkgver.tar.gz
	tls-lwt.patch
	"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --build-dir=.testenv --verbose
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
f2640262b929bece15b51abd3bfcd708eb495fb7371c23e30c2a69f12a1633385d8de90153ee11aaeacb71b3f782f59b3a2f1ce9d783b20c959d9ce6f2f9d96a  ocaml-mqtt-0.2.2.tar.gz
109bfa182d8ca03d2822cc05ae9534676be024b77265ec64fecee45f6ebe7685a869071cb7dcf2e615f36273d739541918fd922e4ef3f1ccb5ab928f4c3f06d6  tls-lwt.patch
"
